package com.ekingstar.framework.util;

import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.context.ApplicationContext;

/**
 * @author Administrator
 */
public class ServiceLocator {

	private static ServiceLocator instance;

	private ServiceLocator() {
	}

	public static synchronized ServiceLocator getInstance() {
		if (instance == null) {
			instance = new ServiceLocator();
		}
		return instance;
	}

	public Object clone() throws CloneNotSupportedException {
		throw new CloneNotSupportedException("ServiceLocator Class不允许复制");
	}

	public Object getBean(String name) {
		Object o = null;
		try {
			o = context.getBean(name);
		} catch (NoSuchBeanDefinitionException ex) {
			System.out.println("Spring getBean(), " + name + "没有找到");

		}
		return o;
	}

	private ApplicationContext context;

	public ApplicationContext getContext() {
		return context;
	}

	public void setContext(ApplicationContext context) {
		this.context = context;
	}
}
